//
//  iMinistryController.m
//  iMinistry
//
//  Created by Jose Luis Garza, Jr on 2/1/11.
//  Copyright 2011 none. All rights reserved.
//

#import "iMinistryController.h"


@implementation iMinistryController

//NSObject

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	
	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
		self.title = @"iMinistry";
	}
	return self;
}

- (void)dealloc {
	[super dealloc];
}


//UIViewController

- (void)loadView {//loadView
	[super loadView];
	
	_launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
	_launcherView.backgroundColor = [UIColor blackColor];
	_launcherView.delegate = self;
	_launcherView.columnCount = 4;
	_launcherView.pages = [NSArray arrayWithObjects:
						   [NSArray arrayWithObjects:
							[[[TTLauncherItem alloc] initWithTitle:@"Blue"
															 image:@"bundle://Icon.png"
															   URL:@"tt://launcherTest/" canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 2"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 3"
															 image:@"bundle://Icon.png"
															   URL:@"fb://item3" canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 4"
															 image:@"bundle://Icon.png"
															   URL:@"fb://item4" canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 5"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 6"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 7"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							nil],
						   [NSArray arrayWithObjects:
							[[[TTLauncherItem alloc] initWithTitle:@"Button 8"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							[[[TTLauncherItem alloc] initWithTitle:@"Button 9"
															 image:@"bundle://Icon.png"
															   URL:nil canDelete:YES] autorelease],
							nil],
						   nil
						   ];
	[self.view addSubview:_launcherView];
	
	TTLauncherItem* item = [_launcherView itemWithURL:@"fb://item3"];
	item.badgeNumber = 4;
	[_launcherView release];
}

- (void) viewDidLoad {
	/*[super viewDidLoad];
	UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:_launcherView action:@selector(beginEditing)];
	self.navigationItem.rightBarButtonItem = editButton;
	[editButton release];*/
}


//TTLauncherViewDelegate

- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item {
	
	[[TTNavigator navigator] openURLAction: [TTURLAction actionWithURLPath:item.URL]];
		
}

- (void)launcherViewDidBeginEditing:(TTLauncherView*)launcher {
	[self.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc]
												 initWithBarButtonSystemItem:UIBarButtonSystemItemDone
												 target:_launcherView action:@selector(endEditing)] autorelease] animated:YES];
}

- (void)launcherViewDidEndEditing:(TTLauncherView*)launcher {
	[self.navigationItem setRightBarButtonItem:nil animated:YES];
}

@end
